﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Resources;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Converter;
using csla4Skeleton.UI.SL.Resources.Utility;
using csla4Skeleton.UI.SL.DanhMuc.DM_NhaCungCap;
using csla4Skeleton.UI.SL.NghiepVu.MuaSanPham.DM_PhuongThucThanhToan;
using csla4Skeleton.UI.SL.NghiepVu.MuaSanPham.DM_LoaiHoaDon;
using csla4Skeleton.UI.SL.NghiepVu.MuaSanPham.DM_LoaiMuaSanPham;
using csla4Skeleton.UI.SL.NghiepVu.MuaSanPham.DM_LoaiTienTe;
using csla4Skeleton.UI.SL.DanhMuc.DM_HangHoa;
using csla4Skeleton.UI.SL.NghiepVu.TienMat.TM_PhieuChi;
using csla4Skeleton.UI.SL.DanhMuc.DM_TaiKhoan;
using csla4Skeleton.UI.SL.DanhMuc.DM_DonViTinh;
using csla4Skeleton.UI.SL.DanhMuc.DM_ThueSuat;
using csla4Skeleton.UI.SL.DanhMuc.DM_TinhChatHangHoa;
using csla4Skeleton.UI.SL.NghiepVu.TaiSanCoDinh.DM_DoiTuongTHCP;
using Accounting.Library;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using System.ComponentModel;
using Utility;
using Accounting.Library.Utility;
using System.Xml;
using ConfigurationNghiepVu;

namespace csla4Skeleton.UI.SL.NghiepVu.MuaSanPham.MSP_MuaDichVu
{
    public partial class MSP_MuaDichVu_MainWindow : UserControl, Csla.Xaml.ISupportNavigation
    {

        #region ISupportNavigation Members
        List<Control> controls = new List<Control>();
        public bool CreateBookmarkAfterLoadCompleted
        {
            get { return true; }
        }

        public event EventHandler LoadCompleted;

        protected virtual void OnLoadCompleted()
        {
            if (LoadCompleted != null)
                LoadCompleted(this, EventArgs.Empty);
            
        }

        public void SetParameters(string parameters)
        {
            try
            {
                if (parameters == "")
                    Khoa = null;
                else
                    Khoa = Int32.Parse(parameters);
            }
            catch
            {
                Khoa = null;
            }
        }

        public string Title
        {
            get { return "MuaDichVu"; }
        }

        #endregion

        #region Load Methods
        private System.Nullable<int> Khoa = null;
        private DM_DoiTuongTHCP_ChildWindow DoiTuongTHCP_ChildWindow;
        List<int> ListOfRowChiTietHasTKNoStartWithSix = new List<int>();
        List<int> ListOfRowChiPhiMuaDichVuHasTKNoStartWithSix = new List<int>();
        public MSP_MuaDichVu_MainWindow(int Khoa)
        {
            this.Khoa = Khoa;
        }

        public MSP_MuaDichVu_MainWindow()
        {
            LocalizationConverter converter = new LocalizationConverter();
            converter.LocalResourceManager = new ResourceManager("csla4Skeleton.UI.SL.NghiepVu.MuaSanPham.MSP_MuaDichVu.Resources", Assembly.GetExecutingAssembly());
            this.Resources.Add("Localization", converter);

            InitializeComponent();
            ControlBehavior.ControlBehaviors.Navigation(this.MSP_MuaDichVu_GeneralInformation_GroupBox, controls);
            ControlBehavior.ControlBehaviors.Navigation(this.MSP_MuaDichVu_MoreInformation_GroupBox, controls);

        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {

                System.Windows.Data.CollectionViewSource MSP_MuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["MSP_MuaDichVu_ViewModelSource"];
                if (Khoa == null)
                {
                    MSP_MuaDichVu_ViewModel MSP_MuaDichVu_ViewModel = new MSP_MuaDichVu_ViewModel();
                    MSP_MuaDichVu_ViewModel.ChildList_AddedNew += new MSP_MuaDichVu_ViewModel.ChildList_AddedNew_EventHandler(MSP_MuaDichVu_ViewModel_ChildList_AddedNew);
                    MSP_MuaDichVu_ViewModel.stateChanged += new MSP_MuaDichVu_ViewModel.DKNV_EventHandler(msp_MuaDichVu_StateChanged);
                    MSP_MuaDichVu_ViewModel.TCHangHoaChanged += new EventHandler(MSP_MuaDichVu_TinhChatHangHoaChanged);
                    MSP_MuaDichVu_ViewModel.hangHoaIdChanged += new MSP_MuaDichVu_ViewModel.HangHoaIdChanged_EventHandler(MSP_MuaDichVu_HangHoaIdChanged);
                    MSP_MuaDichVu_ViewModel.TKCoIdChanged += new MSP_MuaDichVu_ViewModel.TKCoIdChanged_EventHandler(MSP_MuaDichVu_TKCoChanged);
                    MSP_MuaDichVu_ViewModel.LoaiTienTeChanged += new EventHandler(MSP_MuaDichVu_LoaiTienTeChanged);
                    MSP_MuaDichVu_ViewModel.ThueSuatIdChanged += new MSP_MuaDichVu_ViewModel.ThueSuatIdChanged_EventHandler(msp_MuaDichVu_ThueSuatIdChanged);
                    MSP_MuaDichVu_ViewModel.DienGiaiChanged += new MSP_MuaDichVu_ViewModel.DienGiaiChanged_EventHandler(MSP_MuaDichVu_DienGiaiChanged);
                    MSP_MuaDichVu_ViewModel.EnableButtonLapPhieu += new EventHandler(MSP_MuaDichVu_EnableButtonLapPhieu);
                    MSP_MuaDichVu_ViewModel.TKNoIdStartWithSix += new MSP_MuaDichVu_ViewModel.TKNoIdStartWithSix_EventHandler(OnTKNoIdStartWithSix);
                    MSP_MuaDichVu_ViewModel.DoiTuongTHCPIDChanged += new MSP_MuaDichVu_ViewModel.DoiTuongTHCPIDChanged_EventHandler(OnDoiTuongTHCPIDChanged);
                    MSP_MuaDichVu_CollectionViewSource.Source = new List<object> { MSP_MuaDichVu_ViewModel };


                }
                else
                {
                    MSP_MuaDichVu_ViewModel MSP_MuaDichVu_ViewModel = new MSP_MuaDichVu_ViewModel((int)Khoa);
                    MSP_MuaDichVu_ViewModel.ChildList_AddedNew += new MSP_MuaDichVu_ViewModel.ChildList_AddedNew_EventHandler(MSP_MuaDichVu_ViewModel_ChildList_AddedNew);
                    MSP_MuaDichVu_ViewModel.stateChanged += new MSP_MuaDichVu_ViewModel.DKNV_EventHandler(msp_MuaDichVu_StateChanged);
                    MSP_MuaDichVu_ViewModel.TCHangHoaChanged += new EventHandler(MSP_MuaDichVu_TinhChatHangHoaChanged);
                    MSP_MuaDichVu_ViewModel.hangHoaIdChanged += new MSP_MuaDichVu_ViewModel.HangHoaIdChanged_EventHandler(MSP_MuaDichVu_HangHoaIdChanged);
                    MSP_MuaDichVu_ViewModel.TKCoIdChanged += new MSP_MuaDichVu_ViewModel.TKCoIdChanged_EventHandler(MSP_MuaDichVu_TKCoChanged);
                    MSP_MuaDichVu_ViewModel.LoaiTienTeChanged += new EventHandler(MSP_MuaDichVu_LoaiTienTeChanged);
                    MSP_MuaDichVu_ViewModel.ThueSuatIdChanged += new MSP_MuaDichVu_ViewModel.ThueSuatIdChanged_EventHandler(msp_MuaDichVu_ThueSuatIdChanged);
                    MSP_MuaDichVu_ViewModel.DienGiaiChanged += new MSP_MuaDichVu_ViewModel.DienGiaiChanged_EventHandler(MSP_MuaDichVu_DienGiaiChanged);
                    MSP_MuaDichVu_ViewModel.TKNoIdStartWithSix += new MSP_MuaDichVu_ViewModel.TKNoIdStartWithSix_EventHandler(OnTKNoIdStartWithSix);
                    MSP_MuaDichVu_ViewModel.DoiTuongTHCPIDChanged += new MSP_MuaDichVu_ViewModel.DoiTuongTHCPIDChanged_EventHandler(OnDoiTuongTHCPIDChanged);
                    MSP_MuaDichVu_ViewModel.EnableButtonLapPhieu += new EventHandler(MSP_MuaDichVu_EnableButtonLapPhieu);
                    MSP_MuaDichVu_ViewModel.LoadCompleteted += new EventHandler(OnMuaDichVuLoadCompleteted);
                    MSP_MuaDichVu_CollectionViewSource.Source = new List<object> { MSP_MuaDichVu_ViewModel };
                    
                    this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns[this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns.Count - 1].IsVisible = true;
                    this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns[this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns.Count - 2].IsVisible = true;
                    this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns[this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns.Count - 1].IsVisible = true;
                    this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns[this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns.Count - 2].IsVisible = true;

                }

                System.Windows.Data.CollectionViewSource dm_NhaCungCap_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_NhaCungCap_ListViewModelSource"];
                DM_NhaCungCap_ListViewModel dm_NhaCungCap_ListViewModel = new DM_NhaCungCap_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode, BusinessConfiguration.Configuration.DieuKienLocNCC_NhaCungCap);
                dm_NhaCungCap_CollectionViewSource.Source = new List<object> { dm_NhaCungCap_ListViewModel };

                System.Windows.Data.CollectionViewSource dm_PhuongThucThanhToan_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_PhuongThucThanhToan_ListViewModelSource"];
                DM_PhuongThucThanhToan_ListViewModel dm_PhuongThucThanhToan_ListViewModel = new DM_PhuongThucThanhToan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
                dm_PhuongThucThanhToan_CollectionViewSource.Source = new List<object> { dm_PhuongThucThanhToan_ListViewModel };

                System.Windows.Data.CollectionViewSource dm_LoaiHoaDon_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_LoaiHoaDon_ListViewModelSource"];
                DM_LoaiHoaDon_ListViewModel dm_LoaiHoaDon_ListViewModel = new DM_LoaiHoaDon_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
                dm_LoaiHoaDon_CollectionViewSource.Source = new List<object> { dm_LoaiHoaDon_ListViewModel };

                System.Windows.Data.CollectionViewSource dm_DoiTuongTHCP_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_DoiTuongTHCP_ListViewModelSource"];
                DM_DoiTuongTHCP_ListViewModel dm_DoiTuongTHCP_ListViewModel = new DM_DoiTuongTHCP_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
                dm_DoiTuongTHCP_CollectionViewSource.Source = new List<object> { dm_DoiTuongTHCP_ListViewModel };

                System.Windows.Data.CollectionViewSource dm_LoaiTienTe_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_LoaiTienTe_ListViewModelSource"];
                DM_LoaiTienTe_ListViewModel dm_LoaiTienTe_ListViewModel = new DM_LoaiTienTe_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
                dm_LoaiTienTe_CollectionViewSource.Source = new List<object> { dm_LoaiTienTe_ListViewModel };



                System.Windows.Data.CollectionViewSource dm_DonViTinh_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_DonViTinh_ListViewModelSource"];
                DM_DonViTinh_ListViewModel dm_DonViTinh_ListViewModel = new DM_DonViTinh_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
                dm_DonViTinh_CollectionViewSource.Source = new List<object> { dm_DonViTinh_ListViewModel };

                System.Windows.Data.CollectionViewSource dm_ThueSuat_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_ThueSuat_ListViewModelSource"];
                DM_ThueSuat_ListViewModel dm_ThueSuat_ListViewModel = new DM_ThueSuat_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
                dm_ThueSuat_CollectionViewSource.Source = new List<object> { dm_ThueSuat_ListViewModel };

                System.Windows.Data.CollectionViewSource dm_TinhChatHangHoa_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TinhChatHangHoa_ListViewModelSource"];
                DM_TinhChatHangHoa_ListViewModel dm_TinhChatHangHoa_ListViewModel = new DM_TinhChatHangHoa_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
                dm_TinhChatHangHoa_CollectionViewSource.Source = new List<object> { dm_TinhChatHangHoa_ListViewModel };

                DoFilterOnDefaultDKNV1();
                
                DoFilterOnDefaultDM_SanPham();

                

                this.MSP_MuaDichVu_MuaDichVuChiTietGridView.KeyboardCommandProvider = new ControlBehavior.GridViewKeyboardCommandProvider(this.MSP_MuaDichVu_MuaDichVuChiTietGridView);
                this.MSP_MuaDichVu_ThueChiTietGridView.KeyboardCommandProvider = new ControlBehavior.GridViewKeyboardCommandProvider(this.MSP_MuaDichVu_ThueChiTietGridView);
                this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.KeyboardCommandProvider = new ControlBehavior.GridViewKeyboardCommandProvider(this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView);

                ((ControlBehavior.GridViewKeyboardCommandProvider)this.MSP_MuaDichVu_MuaDichVuChiTietGridView.KeyboardCommandProvider).ReachLastColumn += new ControlBehavior.GridViewKeyboardCommandProvider.ReachLastColumn_EventHandler(OnReachLastColumn);
                ((ControlBehavior.GridViewKeyboardCommandProvider)this.MSP_MuaDichVu_ThueChiTietGridView.KeyboardCommandProvider).ReachLastColumn += new ControlBehavior.GridViewKeyboardCommandProvider.ReachLastColumn_EventHandler(OnReachLastColumn);
                ((ControlBehavior.GridViewKeyboardCommandProvider)this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.KeyboardCommandProvider).ReachLastColumn += new ControlBehavior.GridViewKeyboardCommandProvider.ReachLastColumn_EventHandler(OnReachLastColumn);

                ((ControlBehavior.GridViewKeyboardCommandProvider)this.MSP_MuaDichVu_MuaDichVuChiTietGridView.KeyboardCommandProvider).TabKeyPress += new EventHandler(OnTabKeyPress);
                ((ControlBehavior.GridViewKeyboardCommandProvider)this.MSP_MuaDichVu_ThueChiTietGridView.KeyboardCommandProvider).TabKeyPress += new EventHandler(OnTabKeyPress);
                ((ControlBehavior.GridViewKeyboardCommandProvider)this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.KeyboardCommandProvider).TabKeyPress += new EventHandler(OnTabKeyPress);
               
            }
        }

        #endregion

        #region Event Handle
        private void LayoutRoot_KeyUp(object sender, KeyEventArgs e)
        {
            if (Keyboard.Modifiers == ModifierKeys.Control)
            {
                MSP_MuaDichVu_ViewModel vm = GetViewModel();
                if (e.Key == Key.S)
                {
                    if (vm.CanSave)
                    {
                        vm.Save(sender, new Csla.Xaml.ExecuteEventArgs());
                    }
                }
                else if (e.Key == Key.F6)
                {
                    AddItems();
                }
                else if (e.Key == Key.D1)
                {
                    this.MSP_MuaDichVu_MuaDichVuChiTietTab.IsSelected = true;
                }
                else if (e.Key == Key.D2)
                {
                    this.MSP_MuaDichVu_ThueChiTietTab.IsSelected = true;
                }
                else if (e.Key == Key.D3)
                {
                    this.MSP_MuaDichVu_ChiPhiMuaDichVuTab.IsSelected = true;
                }

            }
          
            e.Handled = true;
        }

        void AddItemButton_Click(object sender, RoutedEventArgs e)
        {

            AddItems();
        }

        void DeleteItemButton_Click(object sender, RoutedEventArgs e)
        {
            DeleteItems();

        }

        public void AddItems()
        {
            if (this.MSP_MuaDichVu_MuaDichVuChiTietTab.IsSelected)
            {
                AddMuaDichVuDetailsItem();
            }
        }
        private RadGridView GetActiveGridView()
        {
            if (this.MSP_MuaDichVu_MuaDichVuChiTietTab.IsSelected)
            {
                return MSP_MuaDichVu_MuaDichVuChiTietGridView;
            }
            else if (this.MSP_MuaDichVu_ThueChiTietTab.IsSelected)
            {
                return MSP_MuaDichVu_ThueChiTietGridView;
            }
            else if (this.MSP_MuaDichVu_ChiPhiMuaDichVuTab.IsSelected)
            {
                return MSP_MuaDichVu_ChiPhiMuaDichVuGridView;
            }
           
            return null;
        }



        void DeleteItems()
        {
            if (this.MSP_MuaDichVu_MuaDichVuChiTietTab.IsSelected)
            {
                MSP_MuaDichVu_ChiTietChild ChiTietChild = (MSP_MuaDichVu_ChiTietChild)(this.MSP_MuaDichVu_MuaDichVuChiTietGridView.SelectedItem);
                IList<MSP_MuaDichVu_ChiTietChild> list = GetViewModel().Model.MSP_MuaDichVu_ChiTiets;
                int index = list.IndexOf(ChiTietChild);
               
                DeleteMuaDichVuDetailsItem(index);
            }
           
        }         

        void GridView_AddingNewDataItem(object sender, GridViewAddingNewEventArgs e)
        {
            var grid = e.OwnerGridViewItemsControl;
            if (grid.Items.Count > 0)
            {
                GridViewUtil.FocusRow((RadGridView)grid, grid.Items.Count - 1);
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    grid.CurrentCellInfo = new GridViewCellInfo(grid.Items[grid.Items.Count - 1], grid.Columns[0]);
                    grid.Focus();
                    grid.BeginEdit();
                }));
            }
        }

        private void SaveAndNewButton_Click(object sender, RoutedEventArgs e)
        {
            MSP_MuaDichVu_ViewModel vm = GetViewModel();
            vm.SaveAndNew();
        }

        private void BookedItemButton_Click(object sender, RoutedEventArgs e)
        {
            GetViewModel().GhiSo();
        }

        private void DeleteBookedItemButton_Click(object sender, RoutedEventArgs e)
        {
            GetViewModel().BoGhi();
        }

        private void LapPhieuChiItemButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.GetViewModel().Model.Khoa != 0 && this.GetViewModel().Model.LoaiChungTuId != null)
            {
                System.Windows.Data.CollectionViewSource tm_PhieuChi_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["TM_PhieuChi_ViewModelSource"];
                TM_PhieuChi_ViewModel tm_PhieuChi_ViewModel = new TM_PhieuChi_ViewModel(this.GetViewModel().Model.Khoa, this.GetViewModel().Model.LoaiChungTuId);
                tm_PhieuChi_ViewModel.LoadCompleted += new EventHandler(PhieuChi_LoadCompleted);
                tm_PhieuChi_CollectionViewSource.Source = new List<object> { tm_PhieuChi_ViewModel };
            }
            else
            {
                MessageBoxResult result = MessageBox.Show("Không thể thực hiện chức năng này vi chứng từ không lưu được?", "Thông báo", MessageBoxButton.OK);
            }

            
        }

        private void PhieuChi_LoadCompleted(object sender, EventArgs e)
        {

            System.Windows.Data.CollectionViewSource tm_PhieuChi_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["TM_PhieuChi_ViewModelSource"];
            TM_PhieuChi_ViewModel tm_PhieuChi_ViewModel = ((List<object>)tm_PhieuChi_CollectionViewSource.Source)[0] as TM_PhieuChi_ViewModel;

            if (tm_PhieuChi_ViewModel.Model.Khoa == 0)
            {
                FormNguoiNop formNguoiNop = new FormNguoiNop(this.GetViewModel(), NghiepVuType.MuaDichVu);
                formNguoiNop.Show();
                this.LapPhieuChiItemButton.Content = "Xem phiếu chi";
            }
            else
            {

                TM_PhieuChi_ChildWindow tm_PhieuChi_ChildWindow = new TM_PhieuChi_ChildWindow(tm_PhieuChi_ViewModel, this.GetViewModel(), NghiepVuType.MuaDichVu);
                tm_PhieuChi_ChildWindow.Show();
                tm_PhieuChi_ChildWindow.Visibility = Visibility.Collapsed;
                MessageBoxResult result = MessageBox.Show("Phiếu chi đã tồn tại, bạn có muốn xem phiếu chi không ?", "Xem phiếu chi", MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    tm_PhieuChi_ChildWindow.Visibility = Visibility.Visible;
                    tm_PhieuChi_ChildWindow.CountSave++;

                }
                else if (result == MessageBoxResult.Cancel)
                {
                    tm_PhieuChi_ChildWindow.Close();
                }
            }
        }
        private void DatePicker_KeyUp(object sender, KeyEventArgs e)
        {
            List<Control> availableControl = new List<Control>();
            foreach (Control item in controls)
            {
                if (item.Visibility == System.Windows.Visibility.Visible)
                {
                    availableControl.Add(item);
                }
            }
            Control[] list = availableControl.ToArray();
            if (sender.GetHashCode() == list[availableControl.Count - 1].GetHashCode())
            {
                if (e.Key == Key.Enter)
                {
                    this.AddMuaDichVuDetailsItem();
                }
            }
            else
            {
                ControlBehavior.DatePickerBehaviors.DatePicker_KeyUp(sender, e, controls);
            }
        }

        private void ComboBox_KeyUp(object sender, KeyEventArgs e)
        {
            List<Control> availableControl = new List<Control>();
            foreach (Control item in controls)
            {
                if (item.Visibility == System.Windows.Visibility.Visible)
                {
                    availableControl.Add(item);
                }
            }
            Control[] list = availableControl.ToArray();
            if (sender.GetHashCode() == list[availableControl.Count - 1].GetHashCode())
            {
                if (e.Key == Key.Enter)
                {
                    this.AddMuaDichVuDetailsItem();
                }
            }
            else
            {
                ControlBehavior.ComboBoxBehaviors.ComboBox_KeyUp(sender, e, controls);
            }
        }

        private void Control_KeyUp(object sender, KeyEventArgs e)
        {
            List<Control> availableControl = new List<Control>();
            foreach (Control item in controls)
            {
                if (item.Visibility == System.Windows.Visibility.Visible)
                {
                    availableControl.Add(item);
                }
            }
            Control[] list = availableControl.ToArray();
            if (sender.GetHashCode() == list[availableControl.Count - 1].GetHashCode())
            {
                if (e.Key == Key.Enter)
                {
                    this.AddMuaDichVuDetailsItem();
                }
            }
            else
            {
                ControlBehavior.ControlBehaviors.Control_KeyUp(sender, e, controls);
            }
        }

        void OnTabKeyPress(object sender, EventArgs e)
        {
            this.tabControl.SelectedItem = tabControl.Items[0];
            this.AddMuaDichVuDetailsItem();
        }

        void OnReachLastColumn(object sender, ReachLastColumnArgs e)
        {

            List<TabItem> AvailableTabItem = new List<TabItem>();
            int indexCurrentTab = 0;
            foreach (TabItem item in this.tabControl.Items)
            {
                if (item.Visibility == System.Windows.Visibility.Visible)
                {
                    AvailableTabItem.Add(item);
                    if (item.GetHashCode() == tabControl.SelectedItem.GetHashCode())
                    {
                        indexCurrentTab = AvailableTabItem.IndexOf(item);
                    }

                }
            }


            TabItem[] list = AvailableTabItem.ToArray();
            if (indexCurrentTab == (AvailableTabItem.Count - 1))
            {
                this.tabControl.SelectedItem = list[0];
                FocusAfterChangeTab(this.MSP_MuaDichVu_MuaDichVuChiTietGridView, e.Index);
            }
            else
            {
                this.tabControl.SelectedItem = list[indexCurrentTab + 1];
                if (list[indexCurrentTab + 1].Name.Equals("MSP_MuaDichVu_ChiPhiMuaDichVuTab"))
                {
                    GridViewUtil.FocusRow(this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView, e.Index);
                    FocusAfterChangeTab(this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView, e.Index);
                }
                else if (list[indexCurrentTab + 1].Name.Equals("MSP_MuaDichVu_ThueChiTietTab"))
                {
                    FocusAfterChangeTab(this.MSP_MuaDichVu_ThueChiTietGridView, e.Index);

                }
                

            }

        }

        private void FocusAfterChangeTab(GridViewDataControl grid, int index)
        {
             
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    grid.CurrentCellInfo = new GridViewCellInfo(grid.Items[index], grid.Columns[0]);
                    grid.Focus();
                    grid.BeginEdit();
                }));
          
        }

        private void MSP_MuaDichVu_GeneralInformation_NhaCungCapId_AddItemButton_Click(object sender, RoutedEventArgs e)
        {
            DM_NhaCungCap_ChildWindow dm_NhaCungCap_ChildWindow = new DM_NhaCungCap_ChildWindow();
            dm_NhaCungCap_ChildWindow.Show();
            dm_NhaCungCap_ChildWindow.SaveClicked += new EventHandler(dm_NhaCungCap_ViewModel_Saved);
        }

        private void MSP_MuaDichVu_MoreInformation_PhuongThucThanhToanId_AddItemButton_Click(object sender, RoutedEventArgs e)
        {
            DM_PhuongThucThanhToan_ChildWindow dm_PhuongThucThanhToan_ChildWindow = new DM_PhuongThucThanhToan_ChildWindow();
            dm_PhuongThucThanhToan_ChildWindow.Show();
            dm_PhuongThucThanhToan_ChildWindow.SaveClicked += new EventHandler(dm_PhuongThucThanhToan_ViewModel_Saved);
        }

        private void MSP_MuaDichVu_MoreInformation_LoaiTienId_AddItemButton_Click(object sender, RoutedEventArgs e)
        {
            DM_LoaiTienTe_ChildWindow dm_LoaiTienTe_ChildWindow = new DM_LoaiTienTe_ChildWindow();
            dm_LoaiTienTe_ChildWindow.Show();
            dm_LoaiTienTe_ChildWindow.SaveClicked += new EventHandler(dm_LoaiTienTe_ViewModel_Saved);
        }

        

        #endregion

        #region View Model Related Methods
        private MSP_MuaDichVu_ViewModel GetViewModel()
        {
            System.Windows.Data.CollectionViewSource MSP_MuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["MSP_MuaDichVu_ViewModelSource"];
            return ((List<object>)MSP_MuaDichVu_CollectionViewSource.Source)[0] as MSP_MuaDichVu_ViewModel;
        }

        private void OnMuaDichVuLoadCompleteted(object sender, EventArgs e)
        {
            
            if (this.GetViewModel().Model.DaThanhToan == true && this.GetViewModel().Model.Khoa != 0)
            {
                this.LapPhieuChiItemButton.IsEnabled = true;
               
            }
            else
            {
                this.LapPhieuChiItemButton.IsEnabled = false;
               
            }
        }
        void dm_NhaCungCap_ViewModel_Saved(object sender, EventArgs e)
        {
            System.Windows.Data.CollectionViewSource dm_NhaCungCap_ListViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_NhaCungCap_ListViewModelSource"];
            DM_NhaCungCap_ListViewModel vm = ((List<object>)dm_NhaCungCap_ListViewSource.Source)[0] as DM_NhaCungCap_ListViewModel;
            vm.GetDM_NhaCungCap_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode, BusinessConfiguration.Configuration.DieuKienLocNCC_NhaCungCap);
        }

        void dm_LoaiTienTe_ViewModel_Saved(object sender, EventArgs e)
        {
            System.Windows.Data.CollectionViewSource dm_LoaiTienTe_ListViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_LoaiTienTe_ListViewModelSource"];
            DM_LoaiTienTe_ListViewModel vm = ((List<object>)dm_LoaiTienTe_ListViewSource.Source)[0] as DM_LoaiTienTe_ListViewModel;
            vm.GetDM_LoaiTienTe_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
        }

       

        void dm_PhuongThucThanhToan_ViewModel_Saved(object sender, EventArgs e)
        {
            System.Windows.Data.CollectionViewSource dm_PhuongThucThanhToan_ListViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_PhuongThucThanhToan_ListViewModelSource"];
            DM_PhuongThucThanhToan_ListViewModel vm = ((List<object>)dm_PhuongThucThanhToan_ListViewSource.Source)[0] as DM_PhuongThucThanhToan_ListViewModel;
            vm.GetDM_PhuongThucThanhToan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
        }

        public void DoFilterOnDefaultDM_SanPham()
        {

            System.Windows.Data.CollectionViewSource dm_HangHoa_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_HangHoa_ListViewModelSource"];
            DM_HangHoa_ListViewModel dm_HangHoa_ListViewModel = new DM_HangHoa_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
            dm_HangHoa_CollectionViewSource.Source = new List<object> { dm_HangHoa_ListViewModel };

        }
        void MSP_MuaDichVu_TKCoChanged(object sender, TKCoIdChangedEventArgs e)
        {
           
            if (this.GetViewModel().Model.LoaiHoaDonId == 1 || this.GetViewModel().Model.LoaiHoaDonId == null)
            {
                MSP_MuaDichVu_ChiTietChild ChiTietChild = GetViewModel().Model.MSP_MuaDichVu_ChiTiets[e.Index];
                MSP_MuaDichVu_ThueChild ThueChild = GetViewModel().Model.MSP_MuaDichVu_Thues[e.Index];
                ThueChild.TKCoId = ChiTietChild.TKCoId;
            }

        }
        void MSP_MuaDichVu_TinhChatHangHoaChanged(object sender, EventArgs e)
        {
            int? tinhChatHangHoaId = this.GetViewModel().Model.TinhChatHangHoaId;
            System.Windows.Data.CollectionViewSource dm_HangHoa_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_HangHoa_ListViewModelSource"];
            DM_HangHoa_ListViewModel dm_HangHoa_ListViewModel = ((List<object>)dm_HangHoa_CollectionViewSource.Source)[0] as DM_HangHoa_ListViewModel;
            dm_HangHoa_ListViewModel.GetDM_HangHoa((int)tinhChatHangHoaId);


        }

        void MSP_MuaDichVu_LoaiTienTeChanged(object sender, EventArgs e)
        {

            System.Windows.Data.CollectionViewSource dm_LoaiTienTe_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_LoaiTienTe_ListViewModelSource"];
            DM_LoaiTienTe_ListViewModel dm_LoaiTienTe_ListViewModel = ((List<object>)dm_LoaiTienTe_CollectionViewSource.Source)[0] as DM_LoaiTienTe_ListViewModel;
            IList<DM_LoaiTienTeInfo> list = dm_LoaiTienTe_ListViewModel.Model.getListOfInfo();
            foreach (DM_LoaiTienTeInfo item in list)
            {
                if (item.Khoa == GetViewModel().Model.LoaiTienId)
                {
                    GetViewModel().Model.TyGia = item.TyGiaQuyDoi;
                    break;
                }
            }
        }

        void msp_MuaDichVu_ThueSuatIdChanged(object sender, ThueSuatIdChangedEventArgs e)
        {

            System.Windows.Data.CollectionViewSource dm_ThueSuat_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_ThueSuat_ListViewModelSource"];
            DM_ThueSuat_ListViewModel dm_ThueSuat_ListViewModel = ((List<object>)dm_ThueSuat_CollectionViewSource.Source)[0] as DM_ThueSuat_ListViewModel;

            MSP_MuaDichVu_ThueChild ThueChild = GetViewModel().Model.MSP_MuaDichVu_Thues[e.Index];
            IList<DM_ThueSuatInfo> list = dm_ThueSuat_ListViewModel.Model.getListOfInfo();
            foreach (DM_ThueSuatInfo item in list)
            {
                if (item.Khoa == e.ThueSuatId)
                {
                    ThueChild.ThueSuatValue = item.GiaTriTinhThue;
                }
            }


        }

        void OnTKNoIdStartWithSix(object sender, TKNoIdStartWithSixEventArgs e)
        {
            if (this.MSP_MuaDichVu_MuaDichVuChiTietTab.IsSelected == true)
            {
                System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiTiet_ListViewModelSource"];
                DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiTiet_ListViewModel = ((List<object>)dm_TaiKhoanNo_ChiTiet_CollectionViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
                IList<DM_TaiKhoanInfo> listTaiKhoanNo = dm_TaiKhoanNo_ChiTiet_ListViewModel.Model.getListOfInfo(); ;

                while (ListOfRowChiTietHasTKNoStartWithSix.Count != 0)
                {
                    ListOfRowChiTietHasTKNoStartWithSix.RemoveAt(0);
                }
                int index = 0;
                foreach (MSP_MuaDichVu_ChiTietChild item in this.GetViewModel().Model.MSP_MuaDichVu_ChiTiets)
                {
                    foreach (DM_TaiKhoanInfo itemTaiKhoan in listTaiKhoanNo)
                    {
                        if (item.TKNoId == itemTaiKhoan.Khoa)
                        {
                            if (itemTaiKhoan.Ma.StartsWith("6"))
                            {
                                ListOfRowChiTietHasTKNoStartWithSix.Add(index);
                                break;
                            }
                            else
                            {
                                item.DoiTuongTHCPId = null;
                                item.HangHoa = null;
                            }
                        }
                    }
                    index++;
                }
                if (ListOfRowChiTietHasTKNoStartWithSix.Count != 0)
                {
                    this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns[this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns.Count - 1].IsVisible = true;
                    this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns[this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns.Count - 2].IsVisible = true;

                }
                else
                {
                    this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns[this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns.Count - 1].IsVisible = false;
                    this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns[this.MSP_MuaDichVu_MuaDichVuChiTietGridView.Columns.Count - 2].IsVisible = false;
                }
            }
            else
            {
                System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModelSource"];
                DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel = ((List<object>)dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
                IList<DM_TaiKhoanInfo> listTaiKhoanNo = dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.Model.getListOfInfo(); ;

                while (ListOfRowChiPhiMuaDichVuHasTKNoStartWithSix.Count != 0)
                {
                    ListOfRowChiPhiMuaDichVuHasTKNoStartWithSix.RemoveAt(0);
                }
                int index = 0;
                foreach (MSP_MuaDichVu_ChiPhiMuaDichVuChild item in this.GetViewModel().Model.MSP_MuaDichVu_ChiPhiMuaDichVus)
                {
                    foreach (DM_TaiKhoanInfo itemTaiKhoan in listTaiKhoanNo)
                    {
                        if (item.TkNoId == itemTaiKhoan.Khoa)
                        {
                            if (itemTaiKhoan.Ma.StartsWith("6"))
                            {
                                ListOfRowChiPhiMuaDichVuHasTKNoStartWithSix.Add(index);
                                break;
                            }
                            else
                            {
                                item.DoiTuongTHCPId = null;
                                item.HangHoa = null;
                            }
                        }
                    }
                    index++;
                }
                if (ListOfRowChiPhiMuaDichVuHasTKNoStartWithSix.Count != 0)
                {
                    this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns[this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns.Count - 1].IsVisible = true;
                    this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns[this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns.Count - 2].IsVisible = true;

                }
                else
                {
                    this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns[this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns.Count - 1].IsVisible = false;
                    this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns[this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.Columns.Count - 2].IsVisible = false;
                }
            }
        }

       
        public void OnDoiTuongTHCPIDChanged(object sender, DoiTuongTHCPIDChangedEventArgs e)
        {
            if (this.MSP_MuaDichVu_MuaDichVuChiTietTab.IsSelected == true)
            {
                bool flag = false;
                foreach (int index in ListOfRowChiTietHasTKNoStartWithSix)
                {
                    if (index == e.Index)
                    {
                        flag = true;
                        break;
                    }

                }
                if (this.GetViewModel().Model.MSP_MuaDichVu_ChiTiets[e.Index].DoiTuongTHCPId != null && flag == true)
                {
                    DoiTuongTHCP_ChildWindow = new DM_DoiTuongTHCP_ChildWindow((int)this.GetViewModel().Model.MSP_MuaDichVu_ChiTiets[e.Index].DoiTuongTHCPId, e.Index);
                    DoiTuongTHCP_ChildWindow.Show();
                    DoiTuongTHCP_ChildWindow.Completed += new DM_DoiTuongTHCP_ChildWindow.DoiTuongTHCPId_EventHandler(OnCompleted);
                }
                else
                {
                    this.GetViewModel().Model.MSP_MuaDichVu_ChiTiets[e.Index].DoiTuongTHCPId = null;
                }
            }
            else
            {
                bool flag = false;
                foreach (int index in ListOfRowChiPhiMuaDichVuHasTKNoStartWithSix)
                {
                    if (index == e.Index)
                    {
                        flag = true;
                        break;
                    }

                }
                if (this.GetViewModel().Model.MSP_MuaDichVu_ChiPhiMuaDichVus[e.Index].DoiTuongTHCPId != null && flag == true)
                {
                    DoiTuongTHCP_ChildWindow = new DM_DoiTuongTHCP_ChildWindow((int)this.GetViewModel().Model.MSP_MuaDichVu_ChiPhiMuaDichVus[e.Index].DoiTuongTHCPId, e.Index);
                    DoiTuongTHCP_ChildWindow.Show();
                    DoiTuongTHCP_ChildWindow.Completed += new DM_DoiTuongTHCP_ChildWindow.DoiTuongTHCPId_EventHandler(OnCompleted);
                }
                else
                {
                    this.GetViewModel().Model.MSP_MuaDichVu_ChiPhiMuaDichVus[e.Index].DoiTuongTHCPId = null;
                }
            }
        }
        public void OnCompleted(object sender, DoiTuongTHCPIDChangedEventArgs e)
        {
            if (this.MSP_MuaDichVu_MuaDichVuChiTietTab.IsSelected == true)
            {
                IList<MSP_MuaDichVu_ChiTietChild> list = this.GetViewModel().Model.MSP_MuaDichVu_ChiTiets;
                list[e.Index].HangHoa = DoiTuongTHCP_ChildWindow.SelectedThanhPham;
                DoiTuongTHCP_ChildWindow.Close();
            }
            else
            {
                IList<MSP_MuaDichVu_ChiPhiMuaDichVuChild> list = this.GetViewModel().Model.MSP_MuaDichVu_ChiPhiMuaDichVus;
                list[e.Index].HangHoa = DoiTuongTHCP_ChildWindow.SelectedThanhPham;
                DoiTuongTHCP_ChildWindow.Close();
            }
        }

        void MSP_MuaDichVu_EnableButtonLapPhieu(object sender, EventArgs e)
        {
           
            if (this.GetViewModel().Model.Khoa != 0 && this.GetViewModel().Model.DaThanhToan == true)
            {
                this.LapPhieuChiItemButton.IsEnabled = true;

            }
            else
            {
                this.LapPhieuChiItemButton.IsEnabled = false;
               
            }

        }
        void MSP_MuaDichVu_DienGiaiChanged(object sender, DienGiaiChangedEventArgs e)
        {

            MSP_MuaDichVu_ChiTietChild ChiTietChild = GetViewModel().Model.MSP_MuaDichVu_ChiTiets[e.Index];
            MSP_MuaDichVu_ThueChild ThueChild = GetViewModel().Model.MSP_MuaDichVu_Thues[e.Index];
            MSP_MuaDichVu_ChiPhiMuaDichVuChild ChiPhiMuaDichVuChild = GetViewModel().Model.MSP_MuaDichVu_ChiPhiMuaDichVus[e.Index];

            ChiPhiMuaDichVuChild.DienGiai = "Phụ phí: " + ChiTietChild.DienGiai;
            ThueChild.DienGiai = "GTGT: " + ChiTietChild.DienGiai;

        }

        void MSP_MuaDichVu_HangHoaIdChanged(object sender, HangHoaIdChangedEventArgs e)
        {

            MSP_MuaDichVu_ChiTietChild ChiTietChild = GetViewModel().Model.MSP_MuaDichVu_ChiTiets[e.Index];
            MSP_MuaDichVu_ThueChild ThueChild = GetViewModel().Model.MSP_MuaDichVu_Thues[e.Index];
            MSP_MuaDichVu_ChiPhiMuaDichVuChild ChiPhiMuaDichVuChild = GetViewModel().Model.MSP_MuaDichVu_ChiPhiMuaDichVus[e.Index];
           

            System.Windows.Data.CollectionViewSource dm_HangHoa_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_HangHoa_ListViewModelSource"];
            DM_HangHoa_ListViewModel dm_HangHoa_ListViewModel = ((List<object>)dm_HangHoa_CollectionViewSource.Source)[0] as DM_HangHoa_ListViewModel;
            System.Collections.Generic.IList<DM_HangHoaInfo> list = dm_HangHoa_ListViewModel.Model.getListOfInfo();

            foreach (DM_HangHoaInfo item in list)
            {
                if (item.Khoa == e.HangHoaId)
                {
                    ThueChild.HangHoaId = item.Khoa;
                    ChiPhiMuaDichVuChild.HangHoaId = item.Khoa;
                    break;
                }
            }

        }

        void msp_MuaDichVu_StateChanged(object sender, DieuKienNghiepVuEventArgs e)
        {
            int dknv = 1;
            if (dknv == 1 )
            {
                DoFilterDKNV1();

            }
            else if (dknv == 2)
            {
                DoFilterDKNV2();
            }
            else if (dknv == 3)
            {
                DoFilterDKNV3();

            }

            else if (dknv == 4)
            {
                DoFilterDKNV4();
            }
            else if (dknv == 5)
            {
                DoFilterDKNV5();
            }
            else if (dknv == 6)
            {
                DoFilterDKNV6();
            }
            else if (dknv == 7)
            {
                DoFilterDKNV7();
            }
            else if (dknv == 8)
            {
                DoFilterDKNV8();
            }
        }
        



       

        public void DoFilterOnDefaultDKNV1()
        {
            List<string> taiKhoanNoChiTiet = new List<string>();
            taiKhoanNoChiTiet.Add("1423");
            taiKhoanNoChiTiet.Add("1428");
            taiKhoanNoChiTiet.Add("2423");
            taiKhoanNoChiTiet.Add("2428");
            taiKhoanNoChiTiet.Add("6237");
            taiKhoanNoChiTiet.Add("6238");
            taiKhoanNoChiTiet.Add("6277");
            taiKhoanNoChiTiet.Add("6278");
            taiKhoanNoChiTiet.Add("6417");
            taiKhoanNoChiTiet.Add("6418");
            taiKhoanNoChiTiet.Add("6427");
            taiKhoanNoChiTiet.Add("6428");
            taiKhoanNoChiTiet.Add("811");
            taiKhoanNoChiTiet.Add("635");

            List<string> taiKhoanCoChiTiet = new List<string>();
            taiKhoanCoChiTiet.Add("331");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiTiet_ListViewModel.filterDKNV(taiKhoanNoChiTiet);
            dm_TaiKhoanNo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiTietChanged);
            dm_TaiKhoanNo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiTiet_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.filterDKNV(taiKhoanCoChiTiet);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiTietChanged);
            dm_TaiKhoanCo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiTiet_ListViewModel };


            

            List<string> taiKhoanNoThue = new List<string>();
            taiKhoanNoThue.Add("1331");

            List<string> taiKhoanCoThue = new List<string>();
            taiKhoanCoThue.Add("331");


            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_Thue_ListViewModel.filterDKNV(taiKhoanNoThue);
            dm_TaiKhoanNo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoThueChanged);
            dm_TaiKhoanNo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_Thue_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_Thue_ListViewModel.filterDKNV(taiKhoanCoThue);
            dm_TaiKhoanCo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoThueChanged);
            dm_TaiKhoanCo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_Thue_ListViewModel };

            

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiPhiMuaDichVuChanged);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiPhiMuaDichVuChanged);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel };

        }
        public void DoFilterDKNV1()
        {

            List<string> taiKhoanNoChiTiet = new List<string>();
            taiKhoanNoChiTiet.Add("1423");
            taiKhoanNoChiTiet.Add("1428");
            taiKhoanNoChiTiet.Add("2423");
            taiKhoanNoChiTiet.Add("2428");
            taiKhoanNoChiTiet.Add("6237");
            taiKhoanNoChiTiet.Add("6238");
            taiKhoanNoChiTiet.Add("6277");
            taiKhoanNoChiTiet.Add("6278");
            taiKhoanNoChiTiet.Add("6417");
            taiKhoanNoChiTiet.Add("6418");
            taiKhoanNoChiTiet.Add("6427");
            taiKhoanNoChiTiet.Add("6428");
            taiKhoanNoChiTiet.Add("811");
            taiKhoanNoChiTiet.Add("635");

            List<string> taiKhoanCoChiTiet = new List<string>();
            taiKhoanCoChiTiet.Add("331");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiTiet_ListViewModel.filterDKNV(taiKhoanNoChiTiet);
            dm_TaiKhoanNo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiTiet_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.filterDKNV(taiKhoanCoChiTiet);
            dm_TaiKhoanCo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiTiet_ListViewModel };

            List<string> taiKhoanNoThue = new List<string>();
            taiKhoanNoThue.Add("1331");

            List<string> taiKhoanCoThue = new List<string>();
            taiKhoanCoThue.Add("331");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_Thue_ListViewModel.filterDKNV(taiKhoanNoThue);
            dm_TaiKhoanNo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_Thue_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_Thue_ListViewModel.filterDKNV(taiKhoanCoThue);
            dm_TaiKhoanCo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_Thue_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel = ((List<object>)dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.GetDM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);


            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel = ((List<object>)dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.GetDM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);
            

            dm_TaiKhoanNo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiTietChanged);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiTietChanged);
            dm_TaiKhoanNo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoThueChanged);
            dm_TaiKhoanCo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoThueChanged);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiPhiMuaDichVuChanged);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiPhiMuaDichVuChanged);
        }

        public void DoFilterDKNV2()
        {
            List<string> taiKhoanNoChiTiet = new List<string>();
            taiKhoanNoChiTiet.Add("1421");
            taiKhoanNoChiTiet.Add("2421");

            List<string> taiKhoanCoChiTiet = new List<string>();
            taiKhoanCoChiTiet.Add("331");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiTiet_ListViewModel.filterDKNV(taiKhoanNoChiTiet);
            dm_TaiKhoanNo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiTiet_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.filterDKNV(taiKhoanCoChiTiet);
            dm_TaiKhoanCo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiTiet_ListViewModel };
            
            List<string> taiKhoanNoThue = new List<string>();
            taiKhoanNoThue.Add("1331");

            List<string> taiKhoanCoThue = new List<string>();
            taiKhoanCoThue.Add("331");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_Thue_ListViewModel.filterDKNV(taiKhoanNoThue);
            dm_TaiKhoanNo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_Thue_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_Thue_ListViewModel.filterDKNV(taiKhoanCoThue);
            dm_TaiKhoanCo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_Thue_ListViewModel };

            List<string> taiKhoanNoChiPhiMuaDichVu = new List<string>();
            taiKhoanNoChiPhiMuaDichVu.Add("1421");
            taiKhoanNoChiPhiMuaDichVu.Add("2421");


            List<string> taiKhoanCoChiPhiMuaDichVu = new List<string>();
            taiKhoanCoChiPhiMuaDichVu.Add("1429");
            taiKhoanCoChiPhiMuaDichVu.Add("2429");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.filterDKNV(taiKhoanNoChiPhiMuaDichVu);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.filterDKNV(taiKhoanCoChiPhiMuaDichVu);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel };

            dm_TaiKhoanNo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiTietChanged);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiTietChanged);
            dm_TaiKhoanNo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoThueChanged);
            dm_TaiKhoanCo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoThueChanged);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiPhiMuaDichVuChanged);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiPhiMuaDichVuChanged);
        }
        public void DoFilterDKNV3()
        {
            List<string> taiKhoanNoChiTiet = new List<string>();
            taiKhoanNoChiTiet.Add("1423");
            taiKhoanNoChiTiet.Add("1423");
            taiKhoanNoChiTiet.Add("242");
            taiKhoanNoChiTiet.Add("6237");
            taiKhoanNoChiTiet.Add("6238");
            taiKhoanNoChiTiet.Add("6277");
            taiKhoanNoChiTiet.Add("6278");
            taiKhoanNoChiTiet.Add("6417");
            taiKhoanNoChiTiet.Add("6418");
            taiKhoanNoChiTiet.Add("6427");
            taiKhoanNoChiTiet.Add("6428");
            taiKhoanNoChiTiet.Add("811");
            taiKhoanNoChiTiet.Add("635");

            List<string> taiKhoanCoChiTiet = new List<string>();
            taiKhoanCoChiTiet.Add("331");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiTiet_ListViewModel.filterDKNV(taiKhoanNoChiTiet);
            dm_TaiKhoanNo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiTiet_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.filterDKNV(taiKhoanCoChiTiet);
            dm_TaiKhoanCo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiTiet_ListViewModel };

            List<string> taiKhoanNoThue = new List<string>();
            taiKhoanNoThue.Add("1331");

            List<string> taiKhoanCoThue = new List<string>();
            taiKhoanCoThue.Add("331");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_Thue_ListViewModel.filterDKNV(taiKhoanNoThue);
            dm_TaiKhoanNo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_Thue_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_Thue_ListViewModel.filterDKNV(taiKhoanCoThue);
            dm_TaiKhoanCo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_Thue_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel = ((List<object>)dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.GetDM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);


            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel = ((List<object>)dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.GetDM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);


            dm_TaiKhoanNo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiTietChanged);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiTietChanged);
            dm_TaiKhoanNo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoThueChanged);
            dm_TaiKhoanCo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoThueChanged);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiPhiMuaDichVuChanged);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiPhiMuaDichVuChanged);
        }

        public void DoFilterDKNV4()
        {
            List<string> taiKhoanNoChiTiet = new List<string>();
            taiKhoanNoChiTiet.Add("1421");
            taiKhoanNoChiTiet.Add("2421");

            List<string> taiKhoanCoChiTiet = new List<string>();
            taiKhoanCoChiTiet.Add("331");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiTiet_ListViewModel.filterDKNV(taiKhoanNoChiTiet);
            dm_TaiKhoanNo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiTiet_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.filterDKNV(taiKhoanCoChiTiet);
            dm_TaiKhoanCo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiTiet_ListViewModel };
            
            List<string> taiKhoanNoThue = new List<string>();
            taiKhoanNoThue.Add("1331");
            taiKhoanNoThue.Add("635");

            List<string> taiKhoanCoThue = new List<string>();
            taiKhoanCoThue.Add("331");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_Thue_ListViewModel.filterDKNV(taiKhoanNoThue);
            dm_TaiKhoanNo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_Thue_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_Thue_ListViewModel.filterDKNV(taiKhoanCoThue);
            dm_TaiKhoanCo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_Thue_ListViewModel };

            List<string> taiKhoanNoChiPhiMuaDichVu = new List<string>();
            taiKhoanNoChiPhiMuaDichVu.Add("1421");
            taiKhoanNoChiPhiMuaDichVu.Add("2421");


            List<string> taiKhoanCoChiPhiMuaDichVu = new List<string>();
            taiKhoanCoChiPhiMuaDichVu.Add("1429");
            taiKhoanCoChiPhiMuaDichVu.Add("2429");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.filterDKNV(taiKhoanNoChiPhiMuaDichVu);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.filterDKNV(taiKhoanCoChiPhiMuaDichVu);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel };

            dm_TaiKhoanNo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiTietChanged);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiTietChanged);
            dm_TaiKhoanNo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoThueChanged);
            dm_TaiKhoanCo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoThueChanged);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiPhiMuaDichVuChanged);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiPhiMuaDichVuChanged);
        
        }
        public void DoFilterDKNV5()
        {
            List<string> taiKhoanNoChiTiet = new List<string>();
            taiKhoanNoChiTiet.Add("1423");
            taiKhoanNoChiTiet.Add("1428");
            taiKhoanNoChiTiet.Add("2423");
            taiKhoanNoChiTiet.Add("2428");
            taiKhoanNoChiTiet.Add("6237");
            taiKhoanNoChiTiet.Add("6238");
            taiKhoanNoChiTiet.Add("6277");
            taiKhoanNoChiTiet.Add("6278");
            taiKhoanNoChiTiet.Add("6417");
            taiKhoanNoChiTiet.Add("6418");
            taiKhoanNoChiTiet.Add("6427");
            taiKhoanNoChiTiet.Add("6428");
            taiKhoanNoChiTiet.Add("811");
            taiKhoanNoChiTiet.Add("635");

            List<string> taiKhoanCoChiTiet = new List<string>();
            taiKhoanCoChiTiet.Add("1111");
            taiKhoanCoChiTiet.Add("1121");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiTiet_ListViewModel.filterDKNV(taiKhoanNoChiTiet);
            dm_TaiKhoanNo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiTiet_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.filterDKNV(taiKhoanCoChiTiet);
            dm_TaiKhoanCo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiTiet_ListViewModel };



            List<string> taiKhoanNoThue = new List<string>();
            taiKhoanNoThue.Add("1331");

            List<string> taiKhoanCoThue = new List<string>();
            taiKhoanCoThue.Add("1111");
            taiKhoanCoThue.Add("1121");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_Thue_ListViewModel.filterDKNV(taiKhoanNoThue);
            dm_TaiKhoanNo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_Thue_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_Thue_ListViewModel.filterDKNV(taiKhoanCoThue);
            dm_TaiKhoanCo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_Thue_ListViewModel };


            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel = ((List<object>)dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.GetDM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);


            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel = ((List<object>)dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.GetDM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);


            dm_TaiKhoanNo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiTietChanged);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiTietChanged);
            dm_TaiKhoanNo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoThueChanged);
            dm_TaiKhoanCo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoThueChanged);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiPhiMuaDichVuChanged);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiPhiMuaDichVuChanged);
        }

        public void DoFilterDKNV6()
        {
            List<string> taiKhoanNoChiTiet = new List<string>();
            taiKhoanNoChiTiet.Add("1421");
            taiKhoanNoChiTiet.Add("2421");


            List<string> taiKhoanCoChiTiet = new List<string>();
            taiKhoanCoChiTiet.Add("1111");
            taiKhoanCoChiTiet.Add("1121");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiTiet_ListViewModel.filterDKNV(taiKhoanNoChiTiet);
            dm_TaiKhoanNo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiTiet_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.filterDKNV(taiKhoanCoChiTiet);
            dm_TaiKhoanCo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiTiet_ListViewModel };

            

            List<string> taiKhoanNoThue = new List<string>();
            taiKhoanNoThue.Add("1331");

            List<string> taiKhoanCoThue = new List<string>();
            taiKhoanCoThue.Add("1111");
            taiKhoanCoThue.Add("1121");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_Thue_ListViewModel.filterDKNV(taiKhoanNoThue);
            dm_TaiKhoanNo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_Thue_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_Thue_ListViewModel.filterDKNV(taiKhoanCoThue);
            dm_TaiKhoanCo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_Thue_ListViewModel };

            List<string> taiKhoanNoChiPhiMuaDichVu = new List<string>();
            taiKhoanNoChiPhiMuaDichVu.Add("1421");
            taiKhoanNoChiPhiMuaDichVu.Add("2421");


            List<string> taiKhoanCoChiPhiMuaDichVu = new List<string>();
            taiKhoanCoChiPhiMuaDichVu.Add("1429");
            taiKhoanCoChiPhiMuaDichVu.Add("2429");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.filterDKNV(taiKhoanNoChiPhiMuaDichVu);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.filterDKNV(taiKhoanCoChiPhiMuaDichVu);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel };

            dm_TaiKhoanNo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiTietChanged);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiTietChanged);
            dm_TaiKhoanNo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoThueChanged);
            dm_TaiKhoanCo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoThueChanged);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiPhiMuaDichVuChanged);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiPhiMuaDichVuChanged);
        }

        public void DoFilterDKNV7()
        {
            List<string> taiKhoanNoChiTiet = new List<string>();
            taiKhoanNoChiTiet.Add("1423");
            taiKhoanNoChiTiet.Add("1428");
            taiKhoanNoChiTiet.Add("2423");
            taiKhoanNoChiTiet.Add("2428");
            taiKhoanNoChiTiet.Add("6237");
            taiKhoanNoChiTiet.Add("6238");
            taiKhoanNoChiTiet.Add("6277");
            taiKhoanNoChiTiet.Add("6278");
            taiKhoanNoChiTiet.Add("6417");
            taiKhoanNoChiTiet.Add("6418");
            taiKhoanNoChiTiet.Add("6427");
            taiKhoanNoChiTiet.Add("6428");
            taiKhoanNoChiTiet.Add("811");
            taiKhoanNoChiTiet.Add("635");

            List<string> taiKhoanCoChiTiet = new List<string>();
            taiKhoanCoChiTiet.Add("1112");
            taiKhoanCoChiTiet.Add("1113");
            taiKhoanCoChiTiet.Add("1122");
            taiKhoanCoChiTiet.Add("1123");
            taiKhoanCoChiTiet.Add("515");
            taiKhoanCoChiTiet.Add("007");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiTiet_ListViewModel.filterDKNV(taiKhoanNoChiTiet);
            dm_TaiKhoanNo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiTiet_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.filterDKNV(taiKhoanCoChiTiet);
            dm_TaiKhoanCo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiTiet_ListViewModel };



            List<string> taiKhoanNoThue = new List<string>();
            taiKhoanNoThue.Add("1331");

            List<string> taiKhoanCoThue = new List<string>();
            taiKhoanCoThue.Add("1111");
            taiKhoanCoThue.Add("1121");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_Thue_ListViewModel.filterDKNV(taiKhoanNoThue);
            dm_TaiKhoanNo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_Thue_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_Thue_ListViewModel.filterDKNV(taiKhoanCoThue);
            dm_TaiKhoanCo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_Thue_ListViewModel };


            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel = ((List<object>)dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.GetDM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);


            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel = ((List<object>)dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.GetDM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboboxFetchMode);


            dm_TaiKhoanNo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiTietChanged);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiTietChanged);
            dm_TaiKhoanNo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoThueChanged);
            dm_TaiKhoanCo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoThueChanged);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiPhiMuaDichVuChanged);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiPhiMuaDichVuChanged);
        }
        public void DoFilterDKNV8()
        {
            List<string> taiKhoanNoChiTiet = new List<string>();
            taiKhoanNoChiTiet.Add("1421");
            taiKhoanNoChiTiet.Add("2421");
            taiKhoanNoChiTiet.Add("635");

            List<string> taiKhoanCoChiTiet = new List<string>();
            taiKhoanCoChiTiet.Add("1112");
            taiKhoanCoChiTiet.Add("1113");
            taiKhoanCoChiTiet.Add("1122");
            taiKhoanCoChiTiet.Add("1123");
            taiKhoanCoChiTiet.Add("515");
            taiKhoanCoChiTiet.Add("007");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiTiet_ListViewModel.filterDKNV(taiKhoanNoChiTiet);
            dm_TaiKhoanNo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiTiet_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiTiet_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.filterDKNV(taiKhoanCoChiTiet);
            dm_TaiKhoanCo_ChiTiet_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiTiet_ListViewModel };

            

            List<string> taiKhoanNoThue = new List<string>();
            taiKhoanNoThue.Add("1331");

            List<string> taiKhoanCoThue = new List<string>();
            taiKhoanCoThue.Add("1112");
            taiKhoanCoThue.Add("1113");
            taiKhoanCoThue.Add("1122");
            taiKhoanCoThue.Add("1123");
            taiKhoanCoThue.Add("515");
            taiKhoanCoThue.Add("007");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_Thue_ListViewModel.filterDKNV(taiKhoanNoThue);
            dm_TaiKhoanNo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_Thue_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_Thue_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_Thue_ListViewModel.filterDKNV(taiKhoanCoThue);
            dm_TaiKhoanCo_Thue_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_Thue_ListViewModel };


            List<string> taiKhoanNoChiPhiMuaDichVu = new List<string>();
            taiKhoanNoChiPhiMuaDichVu.Add("1421");
            taiKhoanNoChiPhiMuaDichVu.Add("2421");


            List<string> taiKhoanCoChiPhiMuaDichVu = new List<string>();
            taiKhoanCoChiPhiMuaDichVu.Add("1429");
            taiKhoanCoChiPhiMuaDichVu.Add("2429");

            System.Windows.Data.CollectionViewSource dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.filterDKNV(taiKhoanNoChiPhiMuaDichVu);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_CollectionViewSource.Source = new List<object> { dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel };

            System.Windows.Data.CollectionViewSource dm_TaiKhoanCo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel = new DM_TaiKhoan_ListViewModel(BusinessConfiguration.Configuration.ComboBoxFilterMode);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.filterDKNV(taiKhoanCoChiPhiMuaDichVu);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_CollectionViewSource.Source = new List<object> { dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel };

            dm_TaiKhoanNo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiTietChanged);
            dm_TaiKhoanCo_ChiTiet_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiTietChanged);
            dm_TaiKhoanNo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoThueChanged);
            dm_TaiKhoanCo_Thue_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoThueChanged);
            dm_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanNoChiPhiMuaDichVuChanged);
            dm_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModel.ListTaiKhoanChanged += new EventHandler(OnTaiKhoanCoChiPhiMuaDichVuChanged);
        
        }


        private void OnTaiKhoanNoChiTietChanged(object sender, EventArgs e)
        {
            System.Windows.Data.CollectionViewSource dm_TKNo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TKNo_ChiTiet_ListViewModel = ((List<object>)dm_TKNo_ChiTiet_CollectionViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;

            if (dm_TKNo_ChiTiet_ListViewModel.Model != null && GetViewModel().Model != null)
            {
                System.Collections.Generic.IList<DM_TaiKhoanInfo> listTKNo_ChiTiet = dm_TKNo_ChiTiet_ListViewModel.Model.getListOfInfo();
                IList<MSP_MuaDichVu_ChiTietChild> list = this.GetViewModel().Model.MSP_MuaDichVu_ChiTiets;
                foreach (MSP_MuaDichVu_ChiTietChild item in list)
                {
                    item.TKNoId = listTKNo_ChiTiet[0].Khoa;
                }
            }
        }
        private void OnTaiKhoanNoThueChanged(object sender, EventArgs e)
        {
          
            System.Windows.Data.CollectionViewSource dm_TKNo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TKNo_Thue_ListViewModel = ((List<object>)dm_TKNo_Thue_CollectionViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            if (dm_TKNo_Thue_ListViewModel.Model != null && GetViewModel().Model != null)
            {
                System.Collections.Generic.IList<DM_TaiKhoanInfo> listTKNo_Thue = dm_TKNo_Thue_ListViewModel.Model.getListOfInfo();

                IList<MSP_MuaDichVu_ThueChild> list = this.GetViewModel().Model.MSP_MuaDichVu_Thues;
                foreach (MSP_MuaDichVu_ThueChild item in list)
                {
                    item.TKNoId = listTKNo_Thue[0].Khoa;
                }
            }
        }

        private void OnTaiKhoanNoChiPhiMuaDichVuChanged(object sender, EventArgs e)
        {

            System.Windows.Data.CollectionViewSource dm_TKNo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanNo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TKNo_ChiPhiMuaDichVu_ListViewModel = ((List<object>)dm_TKNo_ChiPhiMuaDichVu_CollectionViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            if (dm_TKNo_ChiPhiMuaDichVu_ListViewModel.Model != null && GetViewModel().Model != null)
            {
                System.Collections.Generic.IList<DM_TaiKhoanInfo> listTKNo_ChiPhiMuaDichVu = dm_TKNo_ChiPhiMuaDichVu_ListViewModel.Model.getListOfInfo();

                IList<MSP_MuaDichVu_ChiPhiMuaDichVuChild> list = this.GetViewModel().Model.MSP_MuaDichVu_ChiPhiMuaDichVus;
                foreach (MSP_MuaDichVu_ChiPhiMuaDichVuChild item in list)
                {
                    item.TkNoId = listTKNo_ChiPhiMuaDichVu[0].Khoa;
                }
            }
        }

       
        private void OnTaiKhoanCoChiTietChanged(object sender, EventArgs e)
        {
            System.Windows.Data.CollectionViewSource dm_TKCo_ChiTiet_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiTiet_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TKCo_ChiTiet_ListViewModel = ((List<object>)dm_TKCo_ChiTiet_CollectionViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            if (dm_TKCo_ChiTiet_ListViewModel.Model != null && GetViewModel().Model != null)
            {
                System.Collections.Generic.IList<DM_TaiKhoanInfo> listTKCo_ChiTiet = dm_TKCo_ChiTiet_ListViewModel.Model.getListOfInfo();

                IList<MSP_MuaDichVu_ChiTietChild> list = this.GetViewModel().Model.MSP_MuaDichVu_ChiTiets;
                foreach (MSP_MuaDichVu_ChiTietChild item in list)
                {
                    item.TKCoId = listTKCo_ChiTiet[0].Khoa;
                }
            }
        }

        private void OnTaiKhoanCoThueChanged(object sender, EventArgs e)
        {
            System.Windows.Data.CollectionViewSource dm_TKCo_Thue_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_Thue_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TKCo_Thue_ListViewModel = ((List<object>)dm_TKCo_Thue_CollectionViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            if (dm_TKCo_Thue_ListViewModel.Model != null && GetViewModel().Model != null)
            {
                System.Collections.Generic.IList<DM_TaiKhoanInfo> listTKCo_Thue = dm_TKCo_Thue_ListViewModel.Model.getListOfInfo();

                IList<MSP_MuaDichVu_ThueChild> list = this.GetViewModel().Model.MSP_MuaDichVu_Thues;
                foreach (MSP_MuaDichVu_ThueChild item in list)
                {
                    item.TKCoId = listTKCo_Thue[0].Khoa;
                }
                
            }
        }

        private void OnTaiKhoanCoChiPhiMuaDichVuChanged(object sender, EventArgs e)
        {

            System.Windows.Data.CollectionViewSource dm_TKCo_ChiPhiMuaDichVu_CollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["DM_TaiKhoanCo_ChiPhiMuaDichVu_ListViewModelSource"];
            DM_TaiKhoan_ListViewModel dm_TKCo_ChiPhiMuaDichVu_ListViewModel = ((List<object>)dm_TKCo_ChiPhiMuaDichVu_CollectionViewSource.Source)[0] as DM_TaiKhoan_ListViewModel;
            if (dm_TKCo_ChiPhiMuaDichVu_ListViewModel.Model != null && GetViewModel().Model != null)
            {
                System.Collections.Generic.IList<DM_TaiKhoanInfo> listTKCo_ChiPhiMuaDichVu = dm_TKCo_ChiPhiMuaDichVu_ListViewModel.Model.getListOfInfo();

                IList<MSP_MuaDichVu_ChiPhiMuaDichVuChild> list = this.GetViewModel().Model.MSP_MuaDichVu_ChiPhiMuaDichVus;
                foreach (MSP_MuaDichVu_ChiPhiMuaDichVuChild item in list)
                {
                    item.TkCoId = listTKCo_ChiPhiMuaDichVu[0].Khoa;
                }
            }
           
        }

       

        private void AddThueDetailsItem()
        {
            GetViewModel().AddMSP_MuaDichVu_ThueItem();
        }

        private void AddMuaDichVuDetailsItem()
        {
            GetViewModel().AddMSP_MuaDichVu_ChiTietItem();
        }

        private void AddChiPhiMuaDichVuDetailsItem()
        {
            GetViewModel().AddMSP_MuaDichVu_ChiPhiMuaDichVuItem();
        }

        

        private void DeleteThueDetailsItem(int Index)
        {
            GetViewModel().DeleteMSP_MuaDichVu_ThueItem(Index);
        }

        private void DeleteMuaDichVuDetailsItem(int Index)
        {
            GetViewModel().DeleteMSP_MuaDichVu_ChiTietItem(Index);
        }

        private void DeleteChiPhiMuaDichVuDetailsItem(int Index)
        {
            GetViewModel().DeleteMSP_MuaDichVu_ChiPhiMuaDichVuItem(Index);
        }

       

        void MSP_MuaDichVu_ViewModel_ChildList_AddedNew(object sender, ChildListAddedNewArgs e)
        {
            if (e.ChildListName == "MSP_MuaDichVu_ChiTiets")
            {
                this.MSP_MuaDichVu_MuaDichVuChiTietGridView.OnAddingNewDataItem(new GridViewAddingNewEventArgs(GetActiveGridView()));
            }
            else if (e.ChildListName == "MSP_MuaDichVu_Thues")
            {
                this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.OnAddingNewDataItem(new GridViewAddingNewEventArgs(GetActiveGridView()));
            }
            else if (e.ChildListName == "MSP_MuaDichVu_ChiPhiMuaDichVus")
            {
                this.MSP_MuaDichVu_ChiPhiMuaDichVuGridView.OnAddingNewDataItem(new GridViewAddingNewEventArgs(GetActiveGridView()));
            }
            
        }


        #endregion

    }
}
